<?php
/*
 * @Author       : chaihao
 * @Date         : 2020-06-01 10:58:11
 * @FilePath     : /ai/controllers/api/RoomController.php
 */

namespace app\controllers\api;

use yii;
use app\commands\ErrorMsg;
use app\commands\Helper;
use app\commands\Validator;
use app\Services\api\RoomService;
use linslin\yii2\curl;



use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\ValidationData;
use http\Exception\RuntimeException;


class RoomController extends ApiController
{

    /**
     * 获取主持人开关
     */
    public function actionGetRoomHost()
    {
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'roomid'  => "required"
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->getRoomHost($req['roomid']);
        Helper::right_out($req, $res);
    }


    /**
     * 房间人数
     *
     */
    public function actionRoomCount()
    {
        $req = $this->req;
        $res = RoomService::getInstance()->getRoomCount();
        Helper::right_out($req, $res);
    }

    /**
     * 加入房间 （房间人数+1）
     */
    public function actionJoinRoom()
    {
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'roomid'  => "required"
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->joinRoom($req['roomid']);
        Helper::right_out($req, $res);
    }


    /**
     * 退出房间
     */
    public function actionQuitRoom()
    {
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'roomid'  => "required"
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $res = RoomService::getInstance()->quitRoom($req['roomid']);
        Helper::right_out($req, $res);
    }
    /**
     * 获取已开启房间基本信息
     */
    public function actionGetList()
    {
        $req = $this->req;
        $res = RoomService::getInstance()->getList();
        Helper::right_out($req, $res);
    }
}
